package com.wwz.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@Data
@TableName("pe_role")
@ApiModel("角色")
public class Role implements Serializable {

    private static final long serialVersionUID = 594829320797158219L;

    @Id
    @ApiModelProperty("主键id")
    private String id;

    @ApiModelProperty("角色名")
    private String name;

    @ApiModelProperty("说明")
    private String description;

    @ApiModelProperty("企业id")
    private String companyId;

    @JsonIgnore
    @ManyToMany(mappedBy="roles")  //不维护中间表
    @TableField(exist = false)
    private Set<User> users = new HashSet<>(0);//角色与用户   多对多


    @JsonIgnore
    @ManyToMany
    @JoinTable(name="pe_role_permission",
            joinColumns={@JoinColumn(name="role_id",referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="permission_id",referencedColumnName="id")})
    @TableField(exist = false)
    private Set<Permission> permissions = new HashSet<Permission>(0);//角色与模块  多对多
}
